#include <bits/stdc++.h>
#define re register
#define int long long
#define Add(a,b) (((a) + (b)) % mod)
#define Sub(a,b) (((a) - (b) + mod) % mod)
#define Mul(a,b) ((a) * (b) % mod)
#define chAdd(a,b) (a = Add(a,b))

using namespace std;

const int N = 1010;
const int mod = 1e9 + 7;
int n,k;
int pw[N];
char s[N],a[N],b[N];

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

inline char getch(int x){ return (!x ? 'L' : 'R'); }

inline bool cmp(char a[],char b[]){ // a >= b
    for (re int i = 1;i <= n;i++){
        if (a[i] < b[i]) return false;
        if (a[i] > b[i]) return true;
    } return true;
}

inline void init(int n){
    pw[0] = 1;
    for (re int i = 1;i <= n;i++) pw[i] = Mul(pw[i - 1],2);
}

namespace Sub1{
    int ans1,ans2;
    char t1[N],t2[N];

    inline void solve(){
        t1[1] = t2[1] = '1';
        for (re int i = 1;i < n;i++){
            if (s[i] == 'R') t1[i + 1] = '1',t2[i + 1] = '0';
            else t1[i + 1] = '0',t2[i + 1] = '1';
        }
        if (cmp(t1,a) && cmp(b,t1)){
            for (re int i = 1;i <= n;i++){
                if (t1[i] == '1') chAdd(ans1,pw[n - i]);
            }
        }
        if (cmp(t2,a) && cmp(b,t2)){
            for (re int i = 1;i <= n;i++){
                if (t2[i] == '1') chAdd(ans2,pw[n - i]);
            }
        } printf("%lld",Add(ans1,ans2));
    }
}

namespace Sub2{
    char o[N];
    int p[N];
    
    inline int calc(int t){
        int ans = 0;
        for (re int i = 1;i <= k;i++) p[i] = 1;
        do{
            int now = t; o[1] = '1';
            for (re int i = 1;i < n;i++){
                if (p[i]) now ^= 1;
                if (!now && s[i] == 'R') o[i + 1] = '1';
                else if (now && s[i] == 'L') o[i + 1] = '1';
                else o[i + 1] = '0';
            }
            if (cmp(o,a) && cmp(b,o)){
                for (re int i = 1;i <= n;i++){
                    cerr << o[i];
                    if (o[i] == '1') chAdd(ans,pw[n - i]);
                }
                cerr << "\n";
            }
        }while (prev_permutation(p + 1,p + n));
        return ans;
    }

    inline void solve(){
        printf("%lld",Add(calc(0),calc(1)));
    }
}

signed main(){
    freopen("lost.in","r",stdin);
    freopen("lost.out","w",stdout);
    n = read(),k = read(); init(n);
    scanf("%s%s%s",s + 1,a + 1,b + 1);
    int lena = strlen(a + 1),lenb = strlen(b + 1);
    for (re int i = lena,j = n;i;i--,j--) a[j] = a[i];
    for (re int i = lenb,j = n;i;i--,j--) b[j] = b[i];
    for (re int i = 1;i <= n - lena;i++) a[i] = '0';
    for (re int i = 1;i <= n - lenb;i++) b[i] = '0';
    if (!k) Sub1::solve();
    else Sub2::solve();
    return 0;
}